home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_052 / tek4010 / tek.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  369 lines

  1. /* This module is a minimum extenal hooks tek 4010 emulation, the
  2.  * function InitTek() must be called before any of the others, it
  3.  * assumes that gfx, intuition are open. Tek() returns true if it
  4.  * uses the input stream else false. It must be called before any 
  5.  * character parsing or you could get into trouble. CloseTek() Frees
  6.  * up all resources used by this module */
  7.  
  8. /* I had to invent a few commands for area fill reset screen, and
  9.  * color setting. Any one who knows the correct commands please let me
  10.  * know  the line drawing and color index selection are standard commands.
  11.  * I have vax software to drive the 640x400 mode, and it works really well.
  12.  * the 1024x790 mode is not quite as clear, but works ok.
  13.  * The author of this software can be contacted as:
  14.  * T.Whelan
  15.  * Dept. of Physics & Astronomy
  16.  * University of Iowa
  17.  * Iowa City
  18.  * IA 52244
  19.  * and on span at IOWA::WHELAN
  20.  
  21.  * on the "to do" list, are graphis input mode and run time selection
  22.  * of the screen resoultion. */
  23.  
  24.  
  25. /*  compiler directives to fetch the necessary header files */
  26. #include "vt100.h"
  27. #include "graphics/display.h"
  28.  
  29. /* this varaible conditionally compiles in one of 2 modes,
  30.  * if TS =  1 you get a 16 color 640x400 screen, the system can not
  31.  * manage to draw sucessfully at 19200 bps in this mode, and the screen
  32.  * on the Amiga 1080 monitor flickers like crazy. (any one know a better
  33.  * monitor for interlace, i.e. one with longer persistance)
  34.  * TS = 2 gives 320x200 32 color screen. It would be simple to put in
  35.  * 6 bit planes to allow extra half bright, but for displaying color
  36.  * graphs that mode is not usefull. This mode runs at 19200 bps. */
  37.  
  38. #define TS 1
  39.  
  40. /* global pointers, used only in this code module */
  41. struct Screen       *TekScreen;
  42. struct Window      *TekWindow;
  43. int *TekFillRas;
  44. extern int * AllocRaster();
  45. /* macros... */
  46. #define mrp TekWindow->RPort
  47. #define COLOR(i, j, k, l) SetRGB4(&TekScreen->ViewPort, i, j, k, l)
  48.  
  49.  
  50. /* this macro puts the tek screen at the back
  51.  * and sets things so that the user gets the
  52.  * non-tek mode of operation, there are some problems here
  53.  * as we do not use intuition to control window positions */
  54. #define TekOFF() {TekMode = FALSE; \
  55.           ScreenToBack(TekScreen); }
  56.  
  57. #define clear() SetRast(mrp, 0); /* set the screen to color Zero */
  58.  
  59. /* the screen size */
  60. #define xmin 0
  61. #define ymin 0 
  62. #define xmax (640/TS)
  63. #define ymax (400/TS)
  64.  
  65. struct NewScreen TekNewScreen = { 
  66.    xmin, ymin,
  67.    xmax, ymax, 3 + TS,
  68.    0, 1,
  69. #if TS == 2
  70.    NULL , 
  71. #else
  72.    HIRES|INTERLACE,
  73. #endif
  74.    CUSTOMSCREEN,
  75.    NULL,
  76.    NULL,
  77.    NULL,
  78.    NULL
  79.    };
  80.  
  81. struct NewWindow TekNewWindow = {
  82.    xmin, ymin,
  83.    xmax, ymax,
  84.    -1, -1,
  85.    RAWKEY,     /* No IDCMP flags */
  86.    BORDERLESS|NOCAREREFRESH|SMART_REFRESH,
  87.    NULL,
  88.    NULL,
  89.    NULL,
  90.    NULL,
  91.    NULL,
  92.    0, 0,
  93.    0, 0,
  94.    CUSTOMSCREEN
  95.    };
  96.  
  97. /* initalise the window and screen needed for this mode
  98.  * inituition and gfx are assumed open */
  99. InitTek(HisPort)
  100. struct MsgPort *HisPort;
  101. {  
  102. static struct AreaInfo ai;
  103. static WORD buffer[250];
  104. static struct TmpRas tr;
  105.  
  106. TekScreen = (struct Screen *)OpenScreen(&TekNewScreen);
  107. if (TekScreen == NULL) return TRUE;
  108.  
  109. TekNewWindow.Screen = TekScreen;
  110. TekWindow = (struct Window *)OpenWindow(&TekNewWindow);
  111. if (TekWindow == NULL) return TRUE;
  112.  
  113. /* make HisPort the User Port for this window, so that his
  114.  * read routines will work when my screen is active
  115.  */
  116. TekWindow->UserPort = HisPort;
  117. ModifyIDCMP(TekWindow, RAWKEY|MENUPICK);
  118.  
  119. /* allow for area fill */
  120. InitArea (ai, buffer, 100);
  121. mrp->AreaInfo = &ai;
  122. TekFillRas = AllocRaster(xmax, ymax);
  123. mrp->TmpRas = InitTmpRas(&tr, TekFillRas, RASSIZE(xmax, ymax));
  124.  
  125. reset();
  126.  
  127. TekScale = 1;
  128. TekOFF();
  129. return FALSE; /* no errors detected */
  130. }
  131.  
  132.  
  133. CloseTek()
  134. {
  135.  TekMode = FALSE;
  136.  FreeRaster(TekFillRas, xmax, ymax);
  137.  TekWindow->UserPort = NULL; /* I will not close his port */
  138.  CloseWindow(TekWindow);
  139.  CloseScreen(TekScreen);
  140. }
  141.  
  142.  
  143. /*************************************************
  144. * Function to do tek 4010 graphics and mode
  145. * switching, the function returns false if it
  146. * uses the character else the
  147. * character can be used for something else
  148. *************************************************/
  149.  
  150.  
  151. int Tek(c)
  152. char c;
  153. {
  154. #define dx 8
  155. #define dy 10
  156.  
  157. static short x = xmin, xl;
  158. static short y = ymin + dy, yl;
  159. static int last, escmode = FALSE, boxmode = FALSE;
  160. static short loy, hix, hiy;
  161. static enum {alpha, line, move, point} mode;
  162. static colormode = NULL, index, red, green;
  163. #define COLORSET  1024
  164. static int tk4100 = NULL;
  165. static int ic = 1;
  166.  
  167. if (TekMode) goto top;
  168. if (c == 29) {
  169.     TekMode = TRUE;
  170.     ScreenToFront(TekScreen);
  171.     mode = move;
  172.     }
  173. return TekMode; /* i.e. if c== 29 we used it and can leave */
  174. top:
  175. if (escmode)
  176.     {
  177.     if (colormode != NULL) {
  178.        c = c - 48;
  179.        colormode++;
  180.        if (colormode == 2)
  181.           index = c;
  182.        else if (colormode == 3)
  183.           red = c;
  184.        else if (colormode == 4)
  185.           green = c;
  186.        else if (colormode == 5) {
  187.            COLOR(index, red, green, c);
  188.            colormode = NULL;
  189.            escmode = FALSE;
  190.         }
  191.        return TekMode;
  192.     }
  193.     switch (c)
  194.     {
  195.     case '2':    /* Selanar Compatable graphics termiante */
  196.           TekOFF();
  197.           boxmode = FALSE;
  198.     break;
  199. /* I do not know what the tek 4100 area fill commands are so I made-up
  200.    my own, this will not harm the line drawing mode. */
  201.     case 'A':
  202.        boxmode = TRUE;
  203.     break;
  204.     case 'B':
  205.       boxmode = FALSE;
  206.     break;
  207.     case 'Q':
  208.       colormode = 1;
  209.     return TekMode;
  210. /* another one of my own commands */
  211.     case 'R':   /* reset to default then clear screen */
  212.         reset();
  213.         ic = 1;
  214.     case 12:     /* clear page */
  215.              x = xmin;
  216.              y = ymin + dy;
  217.         mode = alpha;
  218.         tk4100 = NULL;
  219.         clear();
  220.     break;
  221.     case 'M':  /* looks like a 4100 command */
  222.          tk4100 = 'M';
  223.     break;
  224.     }
  225.     escmode = FALSE;
  226.     }
  227. else if (tk4100 != NULL)
  228.     {
  229.     if (tk4100 == COLORSET)
  230.        ic = c - 48;
  231.        SetAPen(mrp, ic);
  232.       
  233.     if (tk4100 == 'M' && c == 'L')  
  234.        tk4100 = COLORSET;
  235.     else
  236.         tk4100 = NULL;
  237.     }
  238. else if (c >= 32)
  239.     if (mode == alpha)
  240.       {
  241.       SetAPen(mrp, 1);
  242.       Move(mrp,xl,yl);
  243.       Text(mrp,&c,1);
  244.       SetAPen(mrp, ic);
  245.       xl += dx;
  246.       if (xl > xmax) xl = xmax;
  247.       }
  248.     else
  249.       {
  250.         /* a note here about 4014 graphics, If your graphics software
  251.            drives a Tek 4014 then this will work perfecly well, you
  252.            just will not be able to use the 4096 pixel resolution
  253.            that that big storage tube device offers */
  254.       register int tag, data, x, y;
  255.       tag = c/32;
  256.       data = c - tag*32;
  257.       switch (tag)
  258.       {
  259.       case 1:
  260.         if (last == 3)
  261.             hix = data*32;
  262.         else
  263.             hiy = data*32;
  264.       break;
  265.       case 2:
  266.          x = hix + data;   /* low x always sent so don't save it */
  267.          y = hiy + loy;
  268.          if (TekScale == 0)
  269.            {
  270.            x = (x*xmax)/1024;
  271.            y = (y*ymax)/780;
  272.            }
  273.            x = x/TS;
  274.            y = ((ymax-1) -  y/TS);
  275.          switch (mode)
  276.          {
  277.          case move:
  278.              mode = line;
  279.              Move(mrp, x, y);
  280.          break;
  281.          case line:
  282.             if (boxmode)
  283.           RectFill(mrp, 
  284.              min(xl, x), min(yl, y), max(xl, x), max(yl, y));
  285.             else
  286.                Draw(mrp, x, y);
  287.          break;
  288.          case point:
  289.             WritePixel(mrp, x, y);
  290.           break;
  291.           }
  292.       xl = x;
  293.       yl = y;
  294.       break;
  295.       case 3:
  296.          loy = data;
  297.       break;
  298.       }
  299.       last = tag; 
  300.       }
  301. else    switch(c)
  302.     {
  303.     case 7:     /* bell */
  304.          DisplayBeep(NULL);
  305.     break;
  306.     case 8:   /* backspace */
  307.            x -= dx;
  308.            if (x < xmin) x = xmin;
  309.         break;
  310.     case 9:  /* cursor right */
  311.        x += dx;
  312.        if (x > xmax) x = xmax;
  313.     break;
  314.     case 10: /* NL */
  315.          y += dy;
  316.          if (y > ymax) y = ymax;
  317.     break;
  318.     case 11: /* cursor up */
  319.          y -= dy;
  320.          if (y < ymin+dy) y = ymin+dy;
  321.     break;
  322.     case 13:  /* CR */
  323.              x = xmin;
  324.     break;
  325.     case 24:  /* CAN */
  326.         TekOFF();
  327.         boxmode = FALSE;
  328.     break;
  329.     case 27:  /* ESC */
  330.          escmode = TRUE;
  331.     break;
  332.     case 28:  /* FS (point-plot) */
  333.          mode = point;
  334.     break;
  335.     case 29:  /* GS vector */
  336.          mode = move;
  337.     break;
  338.     case 31: /* alpha mode */
  339.          mode = alpha;
  340.     break;
  341.     default:
  342.     break;
  343.       } /* end of switch */
  344.       return TRUE;
  345. }
  346. reset()
  347. {
  348. /* mess up the colors */
  349. COLOR(0, 00, 00, 00);
  350. COLOR(1, 15, 15, 15);
  351. COLOR(2, 15, 00, 00);
  352. COLOR(3, 00, 15, 00);
  353. COLOR(4, 00, 00, 15);
  354. COLOR(5, 00, 15, 15);
  355. COLOR(6, 15, 00, 15);
  356. COLOR(7, 15, 15, 00);
  357. COLOR(8, 15, 08, 00);
  358. COLOR(9, 08, 15, 00);
  359. COLOR(10,00, 15, 08);
  360. COLOR(11,00, 08, 15);
  361. COLOR(12,08, 00, 15);
  362. COLOR(13,15, 00, 08);
  363. COLOR(14,05, 05, 05);
  364. COLOR(15,10, 10, 10);
  365.  
  366. clear();
  367. SetAPen(mrp, 1); 
  368. }
  369.